{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-10-31T07:32:24.008851Z",
     "start_time": "2025-10-31T07:32:24.002400Z"
    }
   },
   "source": [
    "\n",
    "from langgraph.graph import StateGraph, START, END\n",
    "from typing_extensions import TypedDict\n",
    "\n",
    "\n",
    "# Define the state structure~~~~\n",
    "class HelloWorldState(TypedDict):\n",
    "   greeting: str  # This key will store the greeting message\n",
    "\n",
    "# Define the node function\n",
    "def hello_world_node(state: HelloWorldState):\n",
    "    state[\"greeting\"] = \"Hello World, \" + state[\"greeting\"]\n",
    "    return state\n",
    "\n",
    "# Initialize the graph and add the node\n",
    "builder = StateGraph(HelloWorldState)\n",
    "builder.add_node(\"greet\", hello_world_node)\n",
    "\n",
    "# Define the flow of execution using edges\n",
    "builder.add_edge(START, \"greet\")  # Connect START to the \"greet\" node\n",
    "builder.add_edge(\"greet\", END)    # Connect the \"greet\" node to END\n",
    "\n",
    "# Compile and run the graph\n",
    "graph = builder.compile()"
   ],
   "outputs": [],
   "execution_count": 14
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-31T07:32:24.725701Z",
     "start_time": "2025-10-31T07:32:24.024849Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from IPython.display import Image, display\n",
    "\n",
    "try:\n",
    "    display(Image(graph.get_graph().draw_mermaid_png(max_retries=5)))\n",
    "except:\n",
    "    print(\"无法显示流程图\")"
   ],
   "id": "45d2191f803d83b6",
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGoAAADqCAIAAADF80cYAAAQAElEQVR4nOydCXxM597Hn3PObMkkk0T2THZRkuY2SCi1pEVwFbGWUvdSvVRRivbqS7mUj1ZL9bZctNWqpV7Vq5S2KLWEVryC2isr2WWbySSTWc4573NmkpjIme08Rk6S8/34jJnnec6ZnN88+/N/nr+IpmkgwBUREEBAkA8JQT4kBPmQEORDQpAPCVT5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HuTzBfZ5aIbggnmN/V4kKc+X0I4OZGgEfqvULwM4lEG+x/PE4E+ZAQ5ENCkA8JQT4kBPmQ+H8AAAD//2sGWzoAAAAGSURBVAMAzNzD3Rbf3GAAAAAASUVORK5CYII=",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "execution_count": 15
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-31T07:32:24.754868Z",
     "start_time": "2025-10-31T07:32:24.748982Z"
    }
   },
   "cell_type": "code",
   "source": [
    "result = graph.invoke({\"greeting\": \"from LangGraph!\"})\n",
    "print(result)"
   ],
   "id": "db6f69604731516b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'greeting': 'Hello World, from LangGraph!'}\n"
     ]
    }
   ],
   "execution_count": 16
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
